﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverBullet.Graphics;

namespace Microsoft.Xna.Framework.Graphics
{
	/// <summary>
	/// Contains a 2D texture that can be used as a render target.
	/// </summary>
    public class RenderTarget2D : Texture2D//RenderTarget
    {
		private DepthFormat depthFormat;

        void Init(GraphicsDevice graphicsDevice, int width, int height, SurfaceFormat format)
        {
            if (format == SurfaceFormat.Color)
            {
                //_renderer = new CanvasRenderer(width, height);
            }
            else
            {
                //_renderer = new WriteableBitmapRenderer(width, height);
            }
            //_viewport.Width = width;
            //_viewport.Height = height;
			//RenderAtScale = GraphicsDevice.RenderAtScale;
			//BitmapCacheEnabled = GraphicsDevice.BitmapCacheEnabled;
            base.GraphicsDevice = graphicsDevice;
        }

		#region Events
		/// <summary>
		/// Occurs when resources are lost due to a lost device event.
		/// </summary>
		public event EventHandler<EventArgs> ContentLost;
		#endregion

		#region Constructor
		/// <summary>
		/// Creates an instance of this object.
		/// </summary>
		/// <param name="graphicsDevice">The graphics device to associate with this render target resource.</param>
		/// <param name="width">Width, in pixels, of the render target. You can use graphicsDevice.PresentationParameters.BackBufferWidth to get the current screen width.</param>
		/// <param name="height">Height, in pixels, of the render target. You can use graphicsDevice.PresentationParameters.BackBufferHeight to get the current screen height.</param>
		public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height)
			: this(graphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.DiscardContents)
		{
		}

		/// <summary>
		/// Creates an instance of this object.
		/// </summary>
		/// <param name="graphicsDevice">The graphics device to associate with this render target resource.</param>
		/// <param name="width">Width, in pixels, of the render target. You can use graphicsDevice.PresentationParameters.BackBufferWidth to get the current screen width.</param>
		/// <param name="height">Height, in pixels, of the render target. You can use graphicsDevice.PresentationParameters.BackBufferHeight to get the current screen height.</param>
		/// <param name="mipMap">True to enable a full mipmap chain to be generated; otherwise, false.</param>
		/// <param name="preferredFormat">Preferred format for the surface data. This is the format preferred by the application, which may or may not be available from the hardware.</param>
		/// <param name="preferredDepthFormat">Preferred format for the depth buffer. This is the format preferred by the application, which may or may not be available from the hardware.</param>
		public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat)
			: this(graphicsDevice, width, height, mipMap, preferredFormat, preferredDepthFormat, 0, RenderTargetUsage.DiscardContents)
		{
		}

		/// <summary>
		/// Creates an instance of this object.
		/// </summary>
		/// <param name="graphicsDevice">The graphics device to associate with this render target resource.</param>
		/// <param name="width">Width, in pixels, of the render target. You can use graphicsDevice.PresentationParameters.BackBufferWidth to get the current screen width.</param>
		/// <param name="height">Height, in pixels, of the render target. You can use graphicsDevice.PresentationParameters.BackBufferHeight to get the current screen height.</param>
		/// <param name="mipMap">True to enable a full mipmap chain to be generated; otherwise, false.</param>
		/// <param name="preferredFormat">Preferred format for the surface data. This is the format preferred by the application, which may or may not be available from the hardware.</param>
		/// <param name="preferredDepthFormat">Preferred format for the depth buffer. This is the format preferred by the application, which may or may not be available from the hardware.</param>
		/// <param name="preferredMultiSampleCount">The preferred number of multisample locations.</param>
		/// <param name="usage">Behavior options.</param>
		public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
			: base(graphicsDevice, width, height, mipMap, preferredFormat)
		{
			//! TODO: implement remainder
		}
		#endregion

		public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, RenderTargetUsage usage)
			: base(graphicsDevice, width, height, numberLevels, format)
        {
            Init(graphicsDevice, width, height, format);
            //GraphicsDevice._allRenderTargets.Add(this);
        }

        public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, int multiSampleQuality)
			: base(graphicsDevice, width, height, numberLevels, format)
        {
            Init(graphicsDevice, width, height, format);
            //GraphicsDevice._allRenderTargets.Add(this);
        }

        public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, int multiSampleQuality, RenderTargetUsage usage)
			: base(graphicsDevice, width, height, numberLevels, format)
        {
            Init(graphicsDevice, width, height, format);
            //GraphicsDevice._allRenderTargets.Add(this);
        }

		//public Texture2D GetTexture()
		//{
		//    return _renderer.GetTexture(GraphicsDevice);
		//}

		//public bool BitmapCacheEnabled
		//{
		//    get
		//    {
		//        return _renderer.BitmapCacheEnabled;
		//    }
		//    set
		//    {
		//        _renderer.BitmapCacheEnabled = value;
		//    }
		//}

		//public double RenderAtScale
		//{
		//    get
		//    {
		//        return _renderer.RenderAtScale;
		//    }
		//    set
		//    {
		//        _renderer.RenderAtScale = value;
		//    }
		//}
    }
}
